import { Injectable } from '@angular/core';
import { HttpClientService } from '../../../../services/http-client.service';
import { Http } from '@angular/http';
import * as moment from 'moment';

@Injectable()
export class StopRunningService {
  constructor(
    public httpClient: HttpClientService,
    public http: Http
  ) { }
  //  年金查询分页列表
  list(getBody) {
    return this.httpClient.post('/pms/v1/pension/basicInfo/pensionList', getBody);
  }
  //删除组合
  del(putBody) {
    return this.httpClient.put('/pms/v1/pension/basicInfo/deletePension', putBody);
  }
  // 获取附件树
  getFileTree(getBody) {
    return this.httpClient.get('/pms/v1/common/fundFile/attachTree', getBody);
  }
  //修改运作日期
  changeRunningData(putBody) {
    return this.httpClient.put(`/pms/v1/pension/basicInfo/updateBegin?nFundNo=${putBody.nFundNo}&dBegin=${putBody.dBegin}`);
  }
  // 投资经理
  getManagerList() {
    return this.httpClient.get('/pms/v1/common/manager/getProjectManager');
  }
  //项目经理
  getProjectManagerList() {
    return this.httpClient.get('/pms/v1/common/manager/getInstitutions');
  }
  // 获取续约/终止列表数据
  getRenewList(getBody) {
    return this.httpClient.get('/pms/v1/pension/renewTerminationInfo/getPageBasicInfo', getBody);
  }
  // 续约/终止删除
  delRenew(putBody) {
    return this.httpClient.put('/pms/v1/pension/renewTerminationInfo/delBasicInfo', putBody);
  }
  // 续约/终止通过、打回、撤销
  checkRenew(postBody) {
    delete postBody.sStopTypeZh;
    return this.httpClient.put('/pms/v1/pension/renewTerminationInfo/updateAuditStatus', postBody);
  }
  // 续约/终止编辑
  updateRenewTermination(putBody) {
    delete putBody.sStopTypeZh;
    return this.httpClient.put('/pms/v1/pension/renewTerminationInfo/updateBasicInfo', putBody);
  }
  // 续约/终止新增
  addRenew(nFundNo) {
    return this.httpClient.post('/pms/v1/pension/renewTerminationInfo/insertBasicInfoByFundNo?fundNo=' + nFundNo + '&sType=5');
  }
  // 获取基础列表
  getBasicList(getBody) {
    return this.httpClient.post('/pms/v1/pension/basicInfo/pensionList', getBody);
  }
  // 养老金部列表导出,postUrl为请求地址,postBody为请求体,operate为导出文件名
  exportTarget(postUrl, postBody, operate) {
    let today = moment().format('YYYY-MM-DD');
    this.http.post(postUrl, postBody, { responseType: 3 }).map(res => res.json()).subscribe(res => {
      // let blob = new Blob([res], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
      // let blob = new Blob([res], { type: "application/vnd.ms-excel" });
      let blob = new Blob([res], { type: "application/msexcel;charset=UTF-8" });
      if (window.navigator.msSaveOrOpenBlob) {
        navigator.msSaveBlob(blob, operate + today + '.xls');
      } else {
        let resUrl = URL.createObjectURL(blob);
        let a = document.createElement('a');
        document.body.appendChild(a);
        a.setAttribute('style', 'display:none');
        a.setAttribute('href', resUrl);
        a.setAttribute('download', operate + today + '.xls');
        a.click();
        // document.body.removeChild(a);
        // 释放url
        URL.revokeObjectURL(resUrl);
      }
    })
  }
  // 获取备案机构、受托人、托管人下拉框值
  getDictionary() {
    return this.httpClient.get('/pms/v1/common/dict/getStrustee?sFundType=4');
  }
}
